package org.soc.timesheet.server.domain.service;

import java.util.List;
import org.soc.timesheet.domain.UsersProject;
import org.soc.timesheet.domain.repository.UsersProjectRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UsersProjectServiceImpl implements UsersProjectService {
	
	@Override
	public void deleteBySubProject(int idSubProject) {
		// TODO Auto-generated method stub
		usersProjectRepository.deleteBySubProject(idSubProject); 
	}

	public List<UsersProject> findByIdSubProject(int id){
		return usersProjectRepository.findByIdSubProject(id);
	}


	@Autowired
    UsersProjectRepository usersProjectRepository;

	public long countAllUsersProjects() {
        return usersProjectRepository.count();
    }

	public void deleteUsersProject(UsersProject usersProject) {
        usersProjectRepository.delete(usersProject);
    }

	public UsersProject findUsersProject(String id) {
        return usersProjectRepository.findOne(id);
    }

	public List<UsersProject> findAllUsersProjects() {
        return usersProjectRepository.findAll();
    }

	public List<UsersProject> findUsersProjectEntries(int firstResult, int maxResults) {
        return usersProjectRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void saveUsersProject(UsersProject usersProject) {
        usersProjectRepository.save(usersProject);
    }

	public UsersProject updateUsersProject(UsersProject usersProject) {
        return usersProjectRepository.save(usersProject);
    }
}
